@sanity/groq-store
In-memory GROQ store. Streams all available documents from Sanity into an in-memory database and allows you to query them there.
Targets
- Node.js >= 14
- Modern browsers (Edge >= 14, Chrome, Safari, Firefox etc)
Caveats
- Streams entire dataset to memory, so generally not recommended for large datasets
- Needs custom event source to work with tokens in browser
Installation
npm i @sanity/groq-store
Usage
import {groqStore, groq} from '@sanity/groq-store'
const store = groqStore({
projectId: 'abc123',
dataset: 'blog',
listen: true,
overlayDrafts: true,
token: 'someAuthToken',
documentLimit: 10000,
includeTypes: ['post', 'page', 'product', 'sanity.imageAsset'],
})
store.query(groq`*[_type == "author"]`).then((docs) => {
console.log(docs)
})
store.getDocument('grrm').then((grrm) => {
console.log(grrm)
})
store.getDocuments(['grrm', 'jrrt']).then(([grrm, jrrt]) => {
console.log(grrm, jrrt)
})
const sub = store.subscribe(
groq`*[_type == $type][] {name}`,
{type: 'author'},
(err, result) => {
if (err) {
console.error('Oh no, an error:', err)
return
}
console.log('Result:', result)
}
)
sub.unsubscribe()
store.close()
License
MIT © Sanity.io
Release new version
Run "CI & Release" workflow.
Make sure to select the main branch and check "Release new version".
Version will be automatically bumped based on conventional commits since the last release.
Semantic release will only release on configured branches, so it is safe to run release on any branch.
Note: commits with chore:
will be ignored. If you want updated dependencies to trigger
a new version, use fix(deps):
instead.